package org.example;

import java.util.Arrays;
import java.util.Comparator;

public class algorithm_Demo5 {
    public static void main(String[] args) {
        Integer[] arr={1,3,6,4,2,5,10,7,12,9,11,13};
        //Arrays常见之一算法
        //o1-o2：升序排列。
        //o2-o1：降序排列。
        Arrays.sort(arr,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });
        System.out.println(Arrays.toString(arr));
        System.out.println("=============1");
        //二分法查找元素 返回的是索引
        int index1=Arrays.binarySearch(arr,10);
        System.out.println(index1);
        System.out.println("=============2");
        //拷贝数组
        Integer newarr[]=Arrays.copyOf(arr,10);
        System.out.println(Arrays.toString(newarr));
        //拷贝数组 指定范围
        Integer newarr1[]=Arrays.copyOfRange(arr,1,5);
        System.out.println(Arrays.toString(newarr1));
        System.out.println("=============3");
        //填充数组
        Arrays.fill(arr,100);
        System.out.println(Arrays.toString(arr));
        System.out.println("=============4");
        //比较数组
        Integer arr1[]={1,3,6,4,2,5,10,7,12,9,11,13};
        boolean b=Arrays.equals(arr,arr1);
        System.out.println(b);
        System.out.println("=============5");
        //比较数组  范围
        boolean b1=Arrays.equals(arr,1,5,arr1,1,5);
        System.out.println(b1);
        System.out.println("=============6");
        //数组排序  默认方式 升序
        Arrays.sort(arr1,1,5);
        System.out.println(Arrays.toString(arr1));
        System.out.println("=============7");



    }
}
